<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录成功</title>
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
</head>
<script type="text/javascript">
    function refreshToken() {
        $.ajax({
            type: "POST",
            url: "/token/refresh",
            dataType: "json",
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("refresh_token", $("#refresh_token").text());
            },
            success: function (result) {
                $("#user_id").text(result.user_id);
                $("#user_name").text(result.user_detail.user.username);
                $("#nick_name").text(result.user_detail.user.nickName);
                $("#access_token").text(result.access_token);
                $("#access_token_expire").text(result.access_token_expire);
                $("#refresh_token").text(result.refresh_token);
                $("#refresh_token_expire").text(result.refresh_token_expire);
            }
        });
    }

    function logout() {
        $.ajax({
            type: "POST",
            url: "/logout",
            dataType: "json",
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("access_token", $("#access_token").text());
            },
            success: function (result) {
                console.log(result);
                window.location.href = "/login";
            }
        });
    }
</script>
<body>
<h1>登录成功</h1>
<div>用户id：<span th:text="${user.userId}" id="user_id"></span></div>
<br/>
<div>用户名：<span th:text="${user.username}" id="user_name"></span></div>
<br/>
<div>昵称：<span th:text="${user.nickName}" id="nick_name"></span></div>
<br/>
<div>access_token：<span th:text="${token.accessToken}" id="access_token"></span></div>
<br/>
<div>access_token过期时间：<span th:text="${token.accessTokenExpire}" id="access_token_expire"></span>秒</div>
<br/>
<div>refresh_token：<span th:text="${token.refreshToken}" id="refresh_token"></span></div>
<br/>
<div>refresh_token过期时间：<span th:text="${token.refreshTokenExpire}" id="refresh_token_expire"></span>秒</div>
<br/>
<button type="button" onclick="refreshToken()">刷新token</button>
<button type="button" onclick="logout()">退出</button>
</body>
</html>